package org.wordpress.android.listeners;

import android.app.Activity;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;

class GoBackGestureListener extends SimpleOnGestureListener {
    private static final int gestureMaxY = 5;
    private static final int gestureMinX = 10;
    private Activity activity;

    public GoBackGestureListener(Activity activity) {
        super();
        this.activity = activity;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        if (distanceY <= gestureMaxY && distanceX >= gestureMinX) {
            // This is a left-to-right motion so we go back to the last activity
            this.activity.finish();
        }
        return true;
    }
}